﻿namespace Infra.Validation
{
    /// <summary>
    /// Class representing a validation rule.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class ValidationRuleFor<T>
    {
        /// <summary>
        /// Gets the rule number.
        /// </summary>
        /// <value>The rule number.</value>
        public abstract int RuleNumber { get; }
        
        /// <summary>
        /// Gets the next rule to validate.
        /// </summary>
        /// <value>The next rule.</value>
        public abstract ValidationRuleFor<T> NextRule { get; }

        /// <summary>
        /// Validates the concrete rule.
        /// </summary>
        /// <param name="objectToValidate">The object to validate.</param>
        /// <param name="validationResult">The validation result.</param>
        protected abstract void ValidateThisRule(T objectToValidate, ValidationResult validationResult);

        public virtual void ValidateWithResult(T objectToValidate, ValidationResult validationResult)
        {
            this.ValidateThisRule(objectToValidate, validationResult);
        }
    }
}
